package com.v5.mr.sort.mr.string;

import java.io.IOException;

import org.apache.hadoop.conf.Configuration;
import org.apache.hadoop.fs.Path;
import org.apache.hadoop.io.LongWritable;
import org.apache.hadoop.io.NullWritable;
import org.apache.hadoop.io.Text;
import org.apache.hadoop.mapreduce.Job;
import org.apache.hadoop.mapreduce.lib.input.FileInputFormat;
import org.apache.hadoop.mapreduce.lib.output.FileOutputFormat;


/**
 * 字典排序
 * @author zc
 *
 */
public class StringMain {

	public static void main(String[] args) throws Exception {
		// 创建一个任务job = map + reduce
		Job job = Job.getInstance(new Configuration());
		//指定任务的入口
		job.setJarByClass(StringMain.class);
		
		//指定任务的Map和输出的数据类型
		job.setMapperClass(StringMapper.class);
		job.setMapOutputKeyClass(Text.class);
		job.setMapOutputValueClass(NullWritable.class);
		
		//指定我自己的比较器
		job.setSortComparatorClass(MyStringComparator.class);
		
		//指定任务的输出的数据类型
		job.setOutputKeyClass(Text.class);
		job.setOutputValueClass(NullWritable.class); 
		
		//指定输入和输出的HDFS路径
		FileInputFormat.setInputPaths(job, new Path(args[0]));
		FileOutputFormat.setOutputPath(job, new Path(args[1]));
		
		//提交任务
		job.waitForCompletion(true);
	}

}
